package com.feng.show.controller;


import com.alibaba.fastjson.JSON;
import com.feng.show.comm.ResponseCode;
import com.feng.show.comm.ServerResponse;
import com.feng.show.entity.Merchant;
import com.feng.show.service.IMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/merchant")
public class AddPMerchantController {
    /*
    添加经销商
     */

    @Autowired
    private IMerchantService iMerchantServiceImpl;


    @PostMapping("/add")
    public ServerResponse<String> label(

            @RequestParam(value = "merchant") String data,
            @RequestParam(value = "userId") String userId)

    {
        Merchant merchant;
        if (data == null) {
            return ServerResponse.createByErrorMsg("参数错误");
        }

        try{
             merchant= JSON.parseObject(data,Merchant.class);
        }catch(Exception e) {
            return ServerResponse.createByErrorMsg("参数错误");
        }
        return iMerchantServiceImpl.addMerchant(userId,merchant);

    }

    @PostMapping("/getMerchantList")
    public ServerResponse<List<Merchant>> getProductTypeList(

            @RequestParam(value = "userId") String userId)

    {

        userId="10001";
        if(userId==null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ERROR.getCode(),"参数错误");

        }else{
            return iMerchantServiceImpl.getMerchantList(userId) ;
        }

    }










//        if(no==null||name==null||des==null){
//            return ServerResponse.createByErrorCodeMessage(ResponseCode.ERROR.getCode(),"参数错误");
//
//        }else{
//            return addProductTypeService.addProductType(name,no,des);
//        }

    }
//
//    @PostMapping("getProductTypeList")
//    public ServerResponse<List<ProductType>> getProductTypeList(
//
//            @RequestParam(value = "userId") String userId)
//
//    {
//
//        userId="10001";
//        if(userId==null){
//            return ServerResponse.createByErrorCodeMessage(ResponseCode.ERROR.getCode(),"参数错误");
//
//        }else{
//            return addProductTypeService.getProductTypeList(userId);
//        }
//
//    }








